package com.excel.comp;

import java.util.Iterator;

import com.excel.read.HTMLComp;

public class ButtonComp extends HTMLComp{
	String id = "";
	String name = "";
	String onclick = "";
	String value = "";
	/**
	 * 对于新增按钮与修改按钮自动设置事件
	 * 对于其他按钮设置自定义事件
	 */
	public String getParameters() {
		StringBuffer str = new StringBuffer();
		Iterator iter = paramMap.keySet().iterator();
		
		//onclick 事件
		String onclick = null;
		while(iter.hasNext()) {
			String paramKey = (String) iter.next();
			if(!paramKey.equals("id") && !paramKey.equals("onclick")) {
			String value = (String) paramMap.get(paramKey);			
				str.append(" "+paramKey + "=" + value +" ");
			}
			if(paramKey.equals("onclick")) {
				onclick = (String) paramMap.get(paramKey);
			}
		}
		String id = (String) paramMap.get("id");
		str.append(" id=" + this.tableName+ "."+id +" ");
		
		str.append(" name=" + this.tableName+ "."+id +" ");
		this.id = this.tableName+ "."+id;
		
		if(id.equals("btn")) {
			str.append(" onclick= update"+this.tableName+"()");
			this.onclick = " onclick= update"+this.tableName+"()";
		}else if(id.equals("btnNew")) {
			str.append(" onclick= new"+this.tableName+"()");
			this.onclick = " onclick= new"+this.tableName+"()";
		}else {
			//自定义事件
			if(onclick != null) {
				str.append(" onclick = "+onclick);
				this.onclick = " onclick = "+onclick;
			}
		}
		
		value = (String)paramMap.get("value");
		return str.toString();
	}
	
	public String getHTML() {
		System.out.println(getParameters());
		StringBuffer sbf = new StringBuffer();				
		sbf.append("<TABLE class='x-btn-wrap x-btn ' id='"+id+"' name='"+id+"' cellSpacing=0 cellPadding=0 border=0><TBODY><TR><TD class=x-btn-left><I>&nbsp;</I></TD><TD class=x-btn-center><EM unselectable='on'><BUTTON "+onclick+" class=x-btn-text>"+value+"</BUTTON></EM></TD><TD class=x-btn-right><I>&nbsp;</I></TD></TR></TBODY></TABLE>");
		return sbf.toString();
	}

	
	
}
